package com.jiuyuan.config.convert;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @program: hrms
 * @description: 将前台传来的数据进行转换
 * @author: Feng
 * @create: 2023-02-17 13:52
 **/

@Configuration
public class DateTimeConvert implements Converter<String, LocalDate> {


    @Override
    public LocalDate convert(String source) {
        try {
            if(StringUtils.hasText(source))
                return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
